<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>闭包</title>
</head>
<body>
<script type="text/javascript">
    //function fn(){
    //    var num = 100;
    //    console.log(num);
    //    num++;
    //}
    //fn();   //100
    //fn();   //100

    //闭包的缺点：由于内部数据不会被自动销毁，占用内存，所以一般不要使用太多闭包
    function fn(){
        var num =100;
        return function(){
            console.log(num);
            num++;
        };
    }
    var res = fn();
    res();
    res();
    res();
</script>
</body>
</html>